var deviceone = require("deviceone");
var app = deviceone.sm("do_App");
var global = deviceone.sm("do_Global");
var nf = deviceone.sm("do_Notification");
var device=deviceone.sm("do_Device");
//var ln=deviceone.sm("do_LocalNotification");
var tools=require("tools");

// 实例化JPush组件
var jpush = deviceone.sm("do_JPush")
// 订阅JPush的事件
jpush.on("didConnect", function(data, e) {
	deviceone.print(" 返回值：" + JSON.stringify(data)
			+ " 错误信息：" + JSON.stringify(e), "didConnect 事件 ", "didConnect");
});
jpush.on("didLogin", function(data, e) {
	deviceone.print(" 返回值：" + JSON.stringify(data)
			+ " 错误信息：" + JSON.stringify(e), "didLogin 事件 ", "didLogin");
});
jpush.on("didClose", function(data, e) {
	deviceone.print(" 返回值：" + JSON.stringify(data)
			+ " 错误信息：" + JSON.stringify(e), "didClose 事件 ", "didClose");
});
jpush.on("message", function(data, e) {
	// 应用运行在前台时，收到推送消息会触发该事件
	deviceone.print(" 返回值：" + JSON.stringify(data)
			+ " 错误信息：" + JSON.stringify(e), "message 事件 ", "message");
	device.vibrate();
	device.beep();
	if(device.getInfo().OS=="ios"){
		var nowdate=new Date();
		var nowtime=nowdate.getTime();				
		//ln.addNotify(tools.getTime(nowtime.getTime()), notifyId, data.content);
		//notifyId++;
	}
	app.fire("updateIndex");
	//app.fire("updateList");
});
jpush.on("messageClicked", function(data, e) {
	// 应用运行在前台时，收到推送消息会触发该事件
	deviceone.print(" 返回值：" + JSON.stringify(data)
			+ " 错误信息：" + JSON.stringify(e), "messageClicked 事件 ", "messageClicked");
	jpush.setIconBadgeNumber(0);
});
//ln.on("messageClicked",function(){
//	ln.removeNotify();
//});
var regId = jpush.getRegistrationID();
deviceone.print("RegID: " + regId, "JPush init");
jpush.setIconBadgeNumber(0);
app.on("loaded", function() {	
	app.openPage({
		source : "source://view/login.ui",
		data:regId,
		id:"loginID"
	});
});
app.on("setIcon",function(){
	jpush.setIconBadgeNumber(0);
});

